<extend name="Public/base" />
<block name="content">

    <div class="row">
        <div class="medium-3 columns" style="margin-left: 30%;margin-top:5%;margin-bottom: 5%">
            <select  id="types" >
                <option value="0">请选择</option>
                <option value="1">教师账号</option>
                <option value="2">学生账号</option>
            </select>
        </div>
    </div>
    <div style="margin-left: 25%">
        <table id="teaTbl" style="display: none">
            <theat>
                <th>编号</th>
                <th>姓名</th>
                <th>角色</th>
                <th>操作</th>
            </theat>
            <tbody>
            <volist name="arr.tea" id="at">
                <tr>
                    <td><{$at.teacher_id}></td>
                    <td><{$at.tname}></td>
                    <td>
                        <select id="ttt_<{$at.teacher_id}>">
                            <volist name="at.roles" id="atr">
                                <option value="<{$atr.role_id}>" <if condition="$atr['role_id'] eq $at['role_id']">selected</if>><{$atr.role_name}></option>
                            </volist>
                        </select>
                    </td>
                    <td>
                        <button onclick="bct('<{$at.teacher_id}>')" style="height:25px;line-height:6px" class="button tiny radius">保存</button>
                    </td>
                </tr>
            </volist>
            </tbody>
    </table>
    </div>
    <div style="margin-left: 22%">
        <table id="stuTbl" style="display: none">
            <theat>
                <th>编号</th>
                <th>班级</th>
                <th>姓名</th>
                <th>角色</th>
                <th>操作</th>
            </theat>
            <tbody>
            <volist name="arr.stu" id="as">
                <tr>
                    <td><{$as.student_id}></td>
                    <td><{$as.class}></td>
                    <td><{$as.sname}></td>
                    <td>
                        <select id="sss_<{$as.student_id}>">
                            <volist name="as.roles" id="asr">
                                <option value="<{$asr.role_id}>" <if condition="$asr['role_id'] eq $as['role_id']">selected</if>><{$asr.role_name}></option>
                            </volist>
                        </select>
                    </td>
                    <td>
                        <button onclick="bcs('<{$as.student_id}>')" style="height:25px;line-height:6px" class="button tiny radius">保存</button>
                    </td>
                </tr>
            </volist>
            </tbody>
        </table>
    </div>

    <script>
        $('#types ').change(function(){
            if($('#types option:selected').val()=='0'){
                $('#stuTbl').hide();
                $('#teaTbl').hide();
            }else if($('#types option:selected').val()=='1'){
                $('#stuTbl').hide();
                $('#teaTbl').show();
            }else if($('#types option:selected').val()=='2'){
                $('#stuTbl').show();
                $('#teaTbl').hide();
            }
        });
        function bct(a) {
            var data={
              teacher_id:a,
                role_id:$('#ttt_'+a+' option:selected').val(),
            };
            $.post('<{:U("savet")}>',data,function (data) {
                alert(data);
            })
        }
        function bcs(a) {
            var data={
                student_id:a,
                role_id:$('#sss_'+a+' option:selected').val(),
            };
            $.post('<{:U("D/RoleChange/saves")}>',data,function (data) {
                alert(data);
            })
        }
    </script>
</block>